<?php

namespace app\supermanager\controller;

use think\Controller;
use think\Request;
use app\common\traits\controller\TraitController;

class CarCate extends Controller
{
    use TraitController;

    protected function init()
    {
    	if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
        $this->model = model('CarCates');
        $this->list_route = url('/cates');
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $list = $this->model->all();
        return $this->fetch('index',['list'=>$list]);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        return $this->fetch('create');
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        if ($this->model->addInfo($request->post())) {
            $this->success('新增成功', $this->list_route);
        }
        $this->error('新增失败');
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        $info = $this->model->get($id);
        return $this->fetch('read',['info'=>$info]);
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        $info = $this->model->get($id);
        return $this->fetch('edit',['info'=>$info]);
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        if ($this->model->updateInfo($request->post(), ['id' => $id])) {
            $this->success('修改成功', $this->list_route);
        }
        $this->error('修改失败');
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        if ($this->model->delInfo($id)) {
            $this->success('删除成功', $this->list_route);
        }
        $this->error('删除失败');
    }
}
